import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

const store = new Vuex.Store({
	state:{
		token: '',
		userIdData: null,
		requestList: [],
		needBeginLogin: true,
		refreshTokenStatus: false,
		refreshState: false,
		annalsData: {},
		backState: false,
		pageData: null,
		preview: {},
		regnoInfo: null,
		parentRegnoInfo: null,
		LevitatedSphere: {
			startX: -30,
			startY: 600,
			localtionSta: true,
		}
	},
	mutations:{
		setToken(state,value){
			state.token = value;
			if(value){
				let token = value;
				uni.setStorage({
					key: 'token',
					data: token,
				});
			}else{
				uni.removeStorage({
					key: 'token'
				});
			}
		},
		setUserIdData(state,value){
			state.userIdData = value;
			if(value){
				let userIdData = JSON.stringify(value);
				uni.setStorage({
					key: 'userIdData',
					data: userIdData,
				});
			}else{
				uni.removeStorage({
					key: 'userIdData'
				});
			}
		},
		setRegnoInfo(state,value){
			state.regnoInfo = value;
			if(value){
				let regnoInfo = JSON.stringify(value);
				uni.setStorage({
					key: 'regnoInfo',
					data: regnoInfo,
				});
			}else{
				uni.removeStorage({
					key: 'regnoInfo'
				});
			}
		},
		setParentRegnoInfo(state,value){
			state.parentRegnoInfo = value;
			if(value){
				let parentRegnoInfo = JSON.stringify(value);
				uni.setStorage({
					key: 'parentRegnoInfo',
					data: parentRegnoInfo,
				});
			}else{
				uni.removeStorage({
					key: 'parentRegnoInfo'
				});
			}
		},
		setRequestList(state,value){
			state.requestList = value;
		},
		setRefreshState(state,value){
			state.refreshState = value;
		},
		setAnnalsData(state,value){
			state.annalsData = value;
		},
		setBackState(state,value){
			state.backState = value;
		},
		setPageData(state,value){
			state.pageData = value;
		},
		setPreview(state,value){
			state.preview = value;
		},
		setLevitatedSphere(state,value){
			state.LevitatedSphere = value;
		},
	},
	actions:{
		
	}
})

export default store